<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!doctype html>
<html>
<head>
<title>管理操作员</title>
<%@ include file="../common/base.jsp" %>
</head>

<body id="body">
<!--head-->
<div id="head">
	<%@ include file="../common/head.jsp" %>
</div>
<!--head end-->
<!--container-->
<div id="container">
	<div id="pageId" style="display: none;">02-02-01</div>
		<!--sidebar-->
		<%@ include file="../common/menu.jsp" %>
	    <!--sidebar-->
    <!--main-->
    <div class="main">
    	<div class="location" style="background-position:22px -109px;">
        	平台管理<span>&gt;</span>修理中心管理<span>&gt;</span>修理信息管理
        </div>
        <!--content-->
        <div class="content">
			<div class="set_buttons" id="add_button">
				<button type="button" class="btn btn_add" onClick="showRepairInfo();">添加修理中心</button>
			</div>
			<div class="info_container">
				<i style="display:inline-block;">
					<label style="width:210px;text-align:right;min-width:200px;margin-right:6px;" >中心状态：
						<div class="requery_box">
							<select id="state" name="state" style="width: 120px;">
								<option value="1">正常</option>
								<option value="1">不正常</option>
							</select>
						</div>
					</label>
				</i>
				<i style="display:inline-block;">
					<label style="width:400px;" >所属省市信息：
						<div class="requery_box">
							<select id="province" name="province" style="width: 110px;" onchange="changeParentId();">
								<option value="-1">全部</option>
								<c:forEach var="item" items="${districtList}" varStatus="vatS">
									<option value="${item.districtId}">${item.districtName}</option>
								</c:forEach>
							</select>
							<select id="city" name="city" style="width: 110px;">
								<option value="-1">全部</option>
							</select>
						</div>
					</label>
				</i>
				<label style="width: 450px" >
					<i class="sel_date">时间选择：</i>
					<input type="text" id="startTime" class="Wdate"
						   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'1990-01-01'});this.style.border = '1px solid #2A7CCF'" onBlur="this.style.border = '1px solid #D5D5D5'"
						   value="${startTime}"
						   readonly/>
					—
					<input type="text" id="endTime" class="Wdate"
						   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'1990-01-01'});this.style.border = '1px solid #2A7CCF'" onBlur="this.style.border = '1px solid #D5D5D5'"
						   value="${endTime}"
						   readonly/>
				</label>
				<button type="button" class="btn btn_search" id="query_button"></button>
			</div>
            <div id="tableResult">
            	<table class="table_type1">
	                <thead>
	                    <tr>
	                        <th>序号</th>
	                        <th>修理店名</th>
							<th>联系电话</th>
	                        <th>所属省</th>
	                        <th>所属市</th>
	                        <th>所属区</th>
	                        <th>创建时间</th>
	                        <th>操作</th>
	                    </tr>
	                </thead>
	                <tbody id="bodyResult"></tbody>
	            </table>
            </div>
            <div class="page">
                	<div class="itemNum" >
		                    	显示：<select id="selItem">
		                    			<option selected="selected" id="20">20</option>
		                    			<option id="30">30</option>
		                    			<option id="40">40</option>
		                    			<option id="50">50</option>
		                    		</select>条，共 <a id="totalCount" onclick="javascript:void(0);" ></a> 条
		            </div>
                    <ul class="pagination" id="pageCur"></ul>
            </div>
        </div>
        <!--content-->
		<%@ include file="../common/foot.jsp" %>
        <!--foot-->
    </div>
    <!--main-->
</div>
<!--container-->
<script src="${pageContext.request.contextPath}/static/js/basic.js"></script>
<script type="text/javascript">

	function changeParentId(){
	    var parentId = $("#province").val();
        $.ajax({
            type: "POST",
            url: "${pageContext.request.contextPath}/district/queryDistrict",
            dataType:"json",
            data: {
                parentId:parentId
            },
            success: function(data){
				if(data.errorCode == 0){
				    var jo = eval(data.districtList);
				    var html="<option value=\"-1\">全部</option>";
                    for (var i = 0; i < jo.length; i++) {
                        html = html +"<option value='"+jo[i].districtId+"'>"+jo[i].districtName+"</option>"
                    }
                    $("#city").html(html);
                }
            }
        });
	}

//加载ajax请求
function loadResult(page,numPerPage){
	loadResultPerfect(page,numPerPage,"repair/queryRepairDate",retParam());
}

function updateRepairState(id,state){
    var stateName="下架"
    if(state == 1){
        stateName = "下架";
	}
	if(state == 0){
        stateName = "上架";
	}

    prompt.confirm("您确定要"+stateName+"该修理中心吗?",function(){
        $.ajax({
            type: "POST",
            url: "${pageContext.request.contextPath}/repair/updateRepairState",
            dataType:"json",
            data: {
                id:id,
				state:state
            },
            success: function(data){
                prompt.alert(data.msg);
                if (data.errorCode==0) {
                    loadResult(1,$("#selItem").val());
                }
            }
        });
    });
}

// 加载ajax返回结果
function loadTableResult(data){
	var jo = data.json;
	if(jo != '' && jo != null){
		for (var i = 0; i < jo.length; i++) {

		    var opHtml = "<a href='repair/updateRepair?id=" + jo[i].id + "'>修改</a>&nbsp;";
		    var state = jo[i].state;
		    if(state == 0){
                opHtml = opHtml+"<a href='javascript:updateRepairState(" + jo[i].id + ",1)'>上架</a>";
			}else{
                opHtml = opHtml+"<a href='javascript:updateRepairState(" + jo[i].id + ",0)'>下架</a>";
			}


			var content = "<tr>"+
	                    	"<td>"+(i+1)+"</td>" +
							"<td>"+jo[i].repairName+"</td>" +
                			"<td>"+jo[i].phone+"</td>" +
							"<td>"+jo[i].provinceName+"</td>" +
							"<td>"+jo[i].cityName+"</td>" +
                			"<td>"+jo[i].areaName+"</td>" +
							"<td>"+dateFormatTimeLong(jo[i].createTime)+"</td>" +
	                    	"<td>"+opHtml+"</td>"+
	                      "</tr>";
	        $("#bodyResult").append(content);
	    }
	}
}

function del(id){
	
	prompt.confirm("您确定要下架该产品吗?",function(){
			$.ajax({
			   type: "POST",
			   url: "${pageContext.request.contextPath}/aiche/deleteProduct",
			   dataType:"json",
			   data: {
				   id:id
			   },
			   success: function(data){
			   		prompt.alert(data.msg);
					if (data.errorCode==0) {
						loadResult(1,$("#selItem").val());
					}
			   }
		});
	});
}

function resetPwd(operatorId,loginName){
	prompt.confirm("您确定要重置密码吗?",function(){
			$.ajax({
			   type: "POST",
			   url: "${pageContext.request.contextPath}/operatorManagement/resetPwd",
			   dataType:"json",
			   data: {
				   operatorId:operatorId,
				   loginName:loginName
			   },
			   success: function(data){
			   		prompt.alert(data.msg);
					if (data.errorCode==0) {
						loadResult(1,$("#selItem").val());
					}
			   }
		});	
	});
}

function showRepairInfo(){
	window.location.href = "${pageContext.request.contextPath}/repair/showAddRepair";
}

function retParam(){
    var param =  "province=" + $("#province").val() +
			"&city=" + $("#city").val() +
		"&startTime=" + $("#startTime").val() +
        "&endTime=" + $("#endTime").val() +
        "&state=" + $("#state").val();
    return param;
}

//表格排序表头样式
$(document).ready(function(e) {
	loadResult(1,$("#selItem").val());
});

</script>
</body>
</html>